package com.ssu.judea.palmssu.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class UrlImageConverter {
	public static Drawable urlToDrawable(String src) {
		URL urls;
		try {
			urls = new URL(src);
		
		InputStream iss = (InputStream) urls.getContent();
		BitmapDrawable dd = null;
		if (iss != null)
			dd = (BitmapDrawable) Drawable.createFromStream(iss, "src");
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		BitmapDrawable d = null;
		try {
			URL url = new URL(src);
			if (url != null) {
				InputStream is = (InputStream) url.getContent();

				if (is != null)
					d = (BitmapDrawable) Drawable.createFromStream(is, "src");
				
				if (d != null){
					return d;
				}else {
					d = (BitmapDrawable) Drawable.createFromStream(is, "src");
					return d;
				}
			}
		} catch (MalformedURLException e) {
			return null;
		} catch (IOException e) {
			return null;
		}
		return d;
	}
}
